<?php

namespace App\Admin\Controllers\Statistics;

use App\Models\Statistics\Trade;
use Encore\Admin\Facades\Admin;
use Encore\Admin\Layout\Content;
use Encore\Admin\Widgets;
use App\Http\Controllers\Controller;
use Illuminate\Http\Request;

use Encore\Admin\Layout\Row;
use Encore\Admin\Widgets\Box;
use Encore\Admin\Widgets\Callout;

class TradeController extends Controller
{

    public $header = '交易统计';

    /**
     * Index interface.
     *
     * @return Content
     */
    public function index(Request $request)
    {
        return Admin::content(function (Content $content) use ($request) {

            $content->header($this->header);
            $content->description('description');

            $type       = $request->get('type',1);
            $start_time = $request->get('start_time');
            $end_time   = $request->get('end_time');

            $trade = new Trade();
            $transaction_data = $trade->getTransactionData($type,$start_time, $end_time);

            $content->row(view('admin.statistics.transaction-data',['transaction_data'=>$transaction_data]));
            $content->row(view('admin.statistics.customer',['transaction_data'=>$transaction_data]));

            //$content->row(new Box('Bar chart', view('admin.chartjs.bar')));

        });
    }

    public function getTransactionData(Request $request)
    {
        $days_type  = $request->get('days_type','1');
        $start_time = $request->get('start_time');
        $end_time   = $request->get('end_time');

        $trade = new Trade();
        $data = $trade->getTransactionData($days_type,$start_time, $end_time);

        return response()->json(compact('data'));
    }

    public function getSalesVolume(Request $request)
    {
        $days_type  = $request->get('days_type',1);
        $sales_type = $request->get('sales_type');
        $start_time = $request->get('start_time');
        $end_time   = $request->get('end_time');

        $trade = new Trade();
        $data = $trade->getSalesVolume($days_type,$sales_type, $start_time, $end_time);

        return response()->json(compact('name','data'));
    }

    public function getCustomerData(Request $request)
    {

        $mouth_type  = $request->get('mouth_type',1);//1本月 2上月
        $mouth  = $request->get('mouth');
        $trade = new Trade();
        $data = $trade->getCustomerData($mouth_type,$mouth);
    }


}
